package com.newcapec.shiro.utils;


import com.newcapec.shiro.constant.SystemCode;
import lombok.Data;

/**
 * 响应格式类
 */
@Data
public class RestResponse<T> {

    /**
     * 响应代码
     */
    private int code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    public RestResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public RestResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功的响应：新增，编辑，删除
     */
    public static RestResponse success(){
        return new RestResponse(SystemCode.OK.getCode(), SystemCode.OK.getMessage());
    }

    /**
     * 成功的响应：查询
     */
    public static <T> RestResponse success(T data){
        return new RestResponse(SystemCode.OK.getCode(), SystemCode.OK.getMessage(), data);
    }

    /**
     * 失败的响应
     */
    public static RestResponse error(){
        return new RestResponse(SystemCode.Erorr.getCode(), SystemCode.Erorr.getMessage());
    }

    public static RestResponse error(int code, String message){
        return new RestResponse(code, message);
    }
}
